
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>后台代码结构介绍 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.html" />
    
    
    <link rel="prev" href="../hou-tai-dai-ma.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    热度后台交接文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../wen-dang-lian-jie.html">
            
                <a href="../wen-dang-lian-jie.html">
            
                    
                    文档链接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    技术栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../hou-tai-dai-ma.html">
            
                <a href="../hou-tai-dai-ma.html">
            
                    
                    后台代码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.4.1" data-path="hou-tai-dai-ma-jie-gou-jie-shao.html">
            
                <a href="hou-tai-dai-ma-jie-gou-jie-shao.html">
            
                    
                    后台代码结构介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.html">
            
                <a href="fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.html">
            
                    
                    服务器登陆及代码拉取更新
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="ping-mu.html">
            
                <a href="ping-mu.html">
            
                    
                    pm2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="mysql.html">
            
                <a href="mysql.html">
            
                    
                    mysql和sequelizejs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="nginx.html">
            
                <a href="nginx.html">
            
                    
                    nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="apidocs.html">
            
                <a href="apidocs.html">
            
                    
                    apidocs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../lian-xi-wo.html">
            
                <a href="../lian-xi-wo.html">
            
                    
                    更多问题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >后台代码结构介绍</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p><strong>&#x540E;&#x53F0;&#x4EE3;&#x7801;&#x7ED3;&#x6784;&#x4ECB;&#x7ECD;</strong></p>
<p>server &#x76EE;&#x5F55;&#x4E0B;&#x5404;&#x4E2A;&#x76EE;&#x5F55;&#x548C;&#x6587;&#x4EF6;&#x4ECB;&#x7ECD;</p>
<p>bin &#x91CC;&#x9762;&#x6709;server.js &#x540E;&#x53F0;&#x7A0B;&#x5E8F;&#x4E3B;&#x8981;&#x5165;&#x53E3;</p>
<p>common &#x4E00;&#x4E9B;&#x4E34;&#x65F6;&#x6587;&#x4EF6;&#x6216;&#x9759;&#x6001;&#x8D44;&#x6E90;</p>
<p>config &#x76D1;&#x542C;&#x7AEF;&#x53E3;&#x914D;&#x7F6E; &#x548C; &#x6570;&#x636E;&#x5E93;&#x914D;&#x7F6E; &#x5177;&#x4F53;&#x770B;mysql&#x548C;sequelize.js&#x7AE0;&#x8282;</p>
<p>docs &#x63A5;&#x53E3;&#x6587;&#x6863;</p>
<p>node_modules node&#x4F9D;&#x8D56; &#x7248;&#x672C;&#x63A7;&#x5236;&#x4E00;&#x822C;&#x4F1A;&#x5FFD;&#x7565;</p>
<p>qiuniu &#x4E03;&#x725B;&#x4E0A;&#x4F20;&#x6A21;&#x5757;</p>
<p>src &#x4E3B;&#x8981;&#x4EE3;&#x7801;</p>
<p>test &#x6D4B;&#x8BD5;&#x4EE3;&#x7801;</p>
<p>package.json npm&#x4F9D;&#x8D56;&#x548C;&#x547D;&#x4EE4;&#x914D;&#x7F6E;</p>
<p>server.config.js pm2&#x542F;&#x52A8;&#x6587;&#x4EF6; &#x5177;&#x4F53;&#x770B;pm2&#x7AE0;&#x8282;</p>
<p><img src="../assets/1.png" alt=""></p>
<p>src &#x76EE;&#x5F55;&#x4ECB;&#x7ECD;</p>
<p>auth &#x5B58;&#x653E;&#x6F14;&#x793A;&#x7684;&#x6821;&#x9A8C;&#x8EAB;&#x4EFD;&#x7684;&#x4EE3;&#x7801;</p>
<p>config &#x4E00;&#x4E9B;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<p>controller&#x7529;&#x63A5;&#x53E3;&#x4E3B;&#x8981;&#x6587;&#x4EF6;&#x5939;</p>
<p>middleware &#x4E2D;&#x95F4;&#x4EF6;</p>
<p>model &#x6570;&#x636E;&#x5C42; &#x5177;&#x4F53;&#x770B;mysql&#x548C;sequelize.js&#x7AE0;&#x8282;</p>
<p>user &#x6F14;&#x793A;&#x7684;&#x7528;&#x6237;&#x76F8;&#x5173;&#x64CD;&#x4F5C;</p>
<p>utils &#x81EA;&#x5DF1;&#x5C01;&#x88C5;&#x7684;&#x4E00;&#x4E9B;&#x65B9;&#x6CD5;</p>
<p><img src="../assets/2.png" alt=""></p>
<p>src/config &#x76EE;&#x5F55;&#x4ECB;&#x7ECD;</p>
<p>&#x76EE;&#x5F55;&#x4E0B;&#x9762;&#x6709;config.js&#x6587;&#x4EF6; &#x4E3B;&#x8981;&#x5C31;&#x662F;&#x5C01;&#x88C5;&#x4E86;&#x7F51;&#x7EDC;&#x8FD4;&#x56DE;&#x548C;&#x9519;&#x8BEF;&#x7801;&#x4EE5;&#x53CA;&#x4E00;&#x4E9B;&#x70ED;&#x5EA6;&#x6570;&#x636E;&#x7684;&#x5B9A;&#x4E49; &#x5177;&#x4F53;&#x90FD;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x6709;&#x6CE8;&#x91CA;&#x8BF4;&#x660E;</p>
<p>src/controller &#x76EE;&#x5F55;&#x4ECB;&#x7ECD;</p>
<p>controller&#x76EE;&#x5F55;&#x4E0B;&#x6709;&#x4E2A;index.js &#x5B83;&#x662F;&#x5C06;&#x6240;&#x6709;controller&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x76EE;&#x5F55;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x7531;&#x6302;&#x8F7D;&#x51FA;&#x53BB;</p>
<p>controller&#x76EE;&#x5F55;&#x4E0B;&#x9664;index.js&#x5916;&#x90FD;&#x662F;&#x7ED3;&#x6784;&#x4E00;&#x6837;&#x7684;&#x6587;&#x4EF6;&#x5939; &#x6587;&#x4EF6;&#x5939;&#x91CC;&#x9762;&#x90FD;&#x662F; controller.js &#x6587;&#x4EF6; &#x548C; router.js&#x6587;&#x4EF6; &#x4EE5;address&#x6587;&#x4EF6;&#x5939;&#x4E3E;&#x4F8B;:</p>
<p>router.js &#x63A5;&#x53E3;&#x6620;&#x5C04;&#x6587;&#x4EF6;</p>
<p>&#x5148;&#x5BFC;&#x5165;&#x540C;&#x7EA7;&#x76EE;&#x5F55;&#x7684;controller.js &#x7136;&#x540E;&#x4F7F;&#x7528;&#x5B83;&#x5BFC;&#x51FA;&#x7684;&#x65B9;&#x6CD5;</p>
<p>&#x8DEF;&#x7531;&#x914D;&#x7F6E;baseUrl(&#x8DDF;&#x8DEF;&#x7531;) + &#x5BFC;&#x51FA;&#x7684;route(&#x5B50;&#x8DEF;&#x7531;)</p>
<p>&#x7136;&#x540E;&#x7528;&#x6237;&#x8BBF;&#x95EE;&#x670D;&#x52A1;&#x5668;&#x6240;&#x5728;ip + &quot;:&quot; +&#x76D1;&#x542C;&#x7AEF;&#x53E3; + &#x8DDF;&#x8DEF;&#x7531; + &#x5B50;&#x8DEF;&#x7531; &#x4F1A;&#x8C03;&#x7528;handlers&#x4E0B;&#x9762;&#x7684;&#x5BF9;&#x5E94;&#x7684;controller.js &#x7684;&#x65B9;&#x6CD5; &#x8FD4;&#x56DE;</p>
<p>&#x5176;&#x4E2D; &#x5BFC;&#x51FA;&#x7684;&#x6570;&#x7EC4;&#x91CC;&#x9762; &#x5BF9;&#x8C61;&#x5177;&#x4F53;&#x662F; method restful&#x65B9;&#x6CD5; router &#x5B50;&#x8DEF;&#x7531; handlers &#x8C03;&#x7528;&#x65B9;&#x6CD5; &#x9010;&#x6B65;&#x8C03;&#x7528;<img src="../assets/3.png" alt=""></p>
<p>controller.js</p>
<p>controller.js &#x5185;&#x6240;&#x6709;&#x9700;&#x8981;&#x88AB;<code>outer.js</code>&#x8C03;&#x7528;&#x7684;&#x65B9;&#x6CD5;&#x90FD;&#x662F; <code>xport</code>(&#x5BFC;&#x51FA;) <code>sync</code>(&#x5F02;&#x6B65;)&#x51FD;&#x6570;</p>
<p>&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x4E00;&#x822C;&#x6709;&#x4E24;&#x4E2A;&#x53C2;&#x6570; &#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F; ctx &#x662F;&#x4E0A;&#x4E0B;&#x6587;&#x53C2;&#x6570; &#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;next &#x662F;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5; &#x662F;&#x4E4B;&#x524D;router.js&#x91CC;&#x9762;&#x7684; handlers&#x6570;&#x7EC4;&#x91CC;&#x9762;&#x7684;&#x51FD;&#x6570; &#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x662F;&#x5426;&#x8FD8;&#x6709;&#x51FD;&#x6570;&#x6267;&#x884C; &#x4E00;&#x822C;&#x5728;&#x51FD;&#x6570;&#x6267;&#x884C;&#x7684;&#x672B;&#x5C3E;&#x90FD;&#x6709; if(next) {return next()}&#x4EE3;&#x7801;&#x5757;,&#x4E00;&#x822C;&#x901A;&#x8FC7;post&#x8BF7;&#x6C42; &#x53C2;&#x6570;&#x4F1A;&#x5728; ctx.request.body&#x5185; &#x6267;&#x884C;&#x5B8C;&#x6240;&#x6709;&#x65B9;&#x6CD5;&#x540E; ctx.body = xxx &#x8FD4;&#x56DE;&#x7ED9;&#x7528;&#x6237;&#x8C03;&#x7528;&#x7ED3;&#x679C;<img src="../assets/5.png" alt="">src/utils &#x76EE;&#x5F55;&#x4ECB;&#x7ECD;</p>
<p>&#x5C01;&#x88C5;&#x4E86;&#x7528;&#x6237;&#x7684;&#x4E00;&#x4E9B;&#x540E;&#x53F0;&#x64CD;&#x4F5C;&#xFF0C;&#x53D1;&#x9001;&#x9A8C;&#x8BC1;&#x7801;&#x548C;&#x6821;&#x9A8C;&#x9A8C;&#x8BC1;&#x7801;&#x7684;&#x64CD;&#x4F5C;&#x548C;&#x4E00;&#x4E9B;&#x57FA;&#x672C;&#x7684;&#x7ECF;&#x5E38;&#x590D;&#x7528;&#x7684;&#x65B9;&#x6CD5; &#x5177;&#x4F53;&#x4E5F;&#x6709;&#x6CE8;&#x91CA;&#x8BF4;&#x660E;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../hou-tai-dai-ma.html" class="navigation navigation-prev " aria-label="Previous page: 后台代码">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.html" class="navigation navigation-next " aria-label="Next page: 服务器登陆及代码拉取更新">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"后台代码结构介绍","level":"1.4.1","depth":2,"next":{"title":"服务器登陆及代码拉取更新","level":"1.4.2","depth":2,"path":"hou-tai-dai-ma/fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.md","ref":"hou-tai-dai-ma/fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.md","articles":[]},"previous":{"title":"后台代码","level":"1.4","depth":1,"path":"hou-tai-dai-ma.md","ref":"hou-tai-dai-ma.md","articles":[{"title":"后台代码结构介绍","level":"1.4.1","depth":2,"path":"hou-tai-dai-ma/hou-tai-dai-ma-jie-gou-jie-shao.md","ref":"hou-tai-dai-ma/hou-tai-dai-ma-jie-gou-jie-shao.md","articles":[]},{"title":"服务器登陆及代码拉取更新","level":"1.4.2","depth":2,"path":"hou-tai-dai-ma/fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.md","ref":"hou-tai-dai-ma/fu-wu-qi-deng-lu-ji-dai-ma-la-qu-geng-xin.md","articles":[]},{"title":"pm2","level":"1.4.3","depth":2,"path":"hou-tai-dai-ma/ping-mu.md","ref":"hou-tai-dai-ma/ping-mu.md","articles":[]},{"title":"mysql和sequelizejs","level":"1.4.4","depth":2,"path":"hou-tai-dai-ma/mysql.md","ref":"hou-tai-dai-ma/mysql.md","articles":[]},{"title":"nginx","level":"1.4.5","depth":2,"path":"hou-tai-dai-ma/nginx.md","ref":"hou-tai-dai-ma/nginx.md","articles":[]},{"title":"apidocs","level":"1.4.6","depth":2,"path":"hou-tai-dai-ma/apidocs.md","ref":"hou-tai-dai-ma/apidocs.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"hou-tai-dai-ma/hou-tai-dai-ma-jie-gou-jie-shao.md","mtime":"2018-03-19T10:54:57.216Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-03-19T11:14:27.115Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

